﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace NeonMika.EightTracks.Responses
{
    public class AuthentificationResponse : Response
    {
        /*
         * <response>
  <user-token>1;123456789</user-token>
  <current-user>
    <slug>remitest</slug>
    <location></location>
    <popup-prefs>ask</popup-prefs>
    <next-mix-prefs>ask</next-mix-prefs>
    <avatar-urls>
      <sq72>/images/avatars/sq72.jpg</sq72>
      <sq100>/images/avatars/sq100.jpg</sq100>
      <max200>/images/avatars/max200.jpg</max200>
      <sq56>/images/avatars/sq56.jpg</sq56>
    </avatar-urls>
    <bio-html nil="true"></bio-html>
    <subscribed nil="true"></subscribed>
    <login>remitest</login>
    <id>988</id>
    <followed-by-current-user>false</followed-by-current-user>
  </current-user>
  <notices nil="true"></notices>
  <errors nil="true"></errors>
  <status>200 OK</status>
  <logged-in>true</logged-in>
</response>
         * */

        string user_token;

        public string UserToken
        {
            get { return user_token; }
            set { user_token = value; }
        }
        User current_user;

        public User CurrentUser
        {
            get { return current_user; }
            set { current_user = value; }
        }

        public AuthentificationResponse(XElement xml) : base(xml)
        {
            string element = "current-user";
            if ( xml.Element(element) != null && xml.Element(element).Attribute("nil") == null )
                CurrentUser = new User(xml.Element(element));
            else
                CurrentUser = null;

            element = "user-token";
            if ( xml.Element(element) != null && xml.Element(element).Attribute("nil") == null )
                UserToken = xml.Element(element).Value.ToString( );
        }
    }
}
